document.getElementById("run").addEventListener("click", () => {
  let input = document.getElementById("input").value;
  let inNum = Number(input);
  console.log(inNum);
  let output = document.getElementById("output");
  //   使用Number逆序输出数字， 需要考虑负数的情况 -320 -》
  document.getElementById("output").innerHTML =
    "倒序输出情况为：" + calcNumber(inNum);
});

document.getElementById("input").focus();

function calcNumber(n) {
  let num = 0;
  let fu = true;
  // 判断数字的正负，都变成正的计算
  if (n < 0) {
    fu = false;
  }
  n = Math.abs(n);

  while (n > 0) {
    console.log(num);
    let number = Math.floor(n) % 10;
    n = Math.floor(n / 10);
    num = num * 10 + number;
  }

  if (!fu) {
    return -num;
  }
  return num;
}

document.getElementById("input").addEventListener("keyup", function (event) {
  if (event.code === "Enter") {
    // Cancel the default action, if needed
    event.preventDefault();
    // Trigger the button element with a click
    document.getElementById("run").click();
  }
});
